home *** CD-ROM | disk | FTP | other *** search
/ PC Media 4 / PC MEDIA CD04.iso / share / prog / pcl4c42 / dir_io.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-06  |  1.8 KB  |  103 lines

  1. /*
  2. **  DIR_IO.C
  3. **
  4. **  Compile with Microsoft C, Borland Turbo C, or MIX Power C.  You may
  5. **  need to modify the following code for your specfic compiler. Some
  6. **  older versions of Microsoft C do not support directory I/O.
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <dos.h>
  12. #include <string.h>
  13.  
  14. #ifndef FALSE
  15. #define FALSE 0
  16. #endif
  17.  
  18. #ifndef TRUE
  19. #define TRUE !FALSE
  20. #endif
  21.  
  22. /*** define compiler specfic includes ***/
  23.  
  24. #ifdef __POWERC
  25. /* MIX Power C compiler */
  26. #define TURBO_OR_POWERC
  27. #include <direct.h>
  28. #endif
  29.  
  30. #ifdef __TURBOC__
  31. /* Borland Turbo C compiler */
  32. #define TURBO_OR_POWERC
  33. #include <dir.h>
  34. #endif
  35.  
  36. #ifdef _MSC_VER
  37. /* Microsoft C compiler */
  38. static struct _find_t DirStruct;
  39. #endif
  40.  
  41. #ifdef TURBO_OR_POWERC
  42. static char DTAbuffer[256];
  43. static struct ffblk DirStruct;
  44. #endif
  45.  
  46. /*** FindFirst() and FindNext() functions ***/
  47.  
  48. int FindFirst(char *FileSpec,char *Buffer)
  49. {
  50.  
  51. #ifdef TURBO_OR_POWERC
  52.  setdta(DTAbuffer);
  53.  if( findfirst(FileSpec,&DirStruct,0)==0)
  54.    {
  55.     strncpy(Buffer,DirStruct.ff_name,13);
  56.     return(TRUE);
  57.    }
  58.  return(FALSE);
  59. #endif
  60.  
  61. #ifdef _MSC_VER
  62.  if(_dos_findfirst(FileSpec,_A_NORMAL,&DirStruct)==0)
  63.    {
  64.     strncpy(Buffer,DirStruct.name,13);
  65.     return(TRUE);
  66.    }
  67.  return(FALSE);
  68. #endif
  69.  
  70. #ifdef _QC
  71.  /* Quick C has no "FindFirst" function */
  72.  strcpy(Buffer,FileSpec);
  73. #endif
  74. }
  75.  
  76. int FindNext(char *Buffer)
  77. {int Result;
  78.  
  79. #ifdef TURBO_OR_POWERC
  80.  if( findnext(&DirStruct)==0 )
  81.    {
  82.     strncpy(Buffer,DirStruct.ff_name,13);
  83.     return(TRUE);
  84.    }
  85.  return(FALSE);
  86. #endif
  87.  
  88. #ifdef _MSC_VER
  89. Result = _dos_findnext(&DirStruct);
  90. if(Result==0)
  91.    {
  92.     strncpy(Buffer,DirStruct.name,13);
  93.     return(TRUE);
  94.    }
  95.  return(FALSE);
  96. #endif
  97.  
  98. #ifdef _QC
  99.  /* Quick C has no "FindNext" function */
  100.  return(FALSE);
  101. #endif
  102.  
  103. }